package lab3;

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

/**
 * JUnit测试运行器，用于运行所有测试类
 * 可以在IDE中直接运行此类来执行所有测试
 */
public class JUnitTestRunner {
    public static void main(String[] args) {
        System.out.println("开始运行ArithmeticExpressionTest...");
        runTests(ArithmeticExpressionTest.class);
        
        System.out.println("\n开始运行ExpressionInheritanceTest...");
        runTests(ExpressionInheritanceTest.class);
        
        System.out.println("\n开始运行ExerciseTest...");
        runTests(ExerciseTest.class);
        
        System.out.println("\n所有测试类已成功配置为使用JUnit框架！");
    }
    
    private static void runTests(Class<?> testClass) {
        Result result = JUnitCore.runClasses(testClass);
        int successCount = result.getRunCount() - result.getFailureCount();
        
        System.out.println("运行了 " + result.getRunCount() + " 个测试");
        System.out.println("成功了 " + successCount + " 个测试");
        System.out.println("失败了 " + result.getFailureCount() + " 个测试");
        
        for (Failure failure : result.getFailures()) {
            System.out.println("失败: " + failure.toString());
            System.out.println(failure.getTrace());
        }
        
        System.out.println("测试结果: " + (result.wasSuccessful() ? "成功" : "失败"));
    }
}